package com.nosweattechnet.datatypes;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nosweattechnet.mapmyway.R;

//Allows for items to be displayed in a ListView
public class ItemListAdapter extends ArrayAdapter<Item>
{
	int resource;
	Context context;
	
	//Creates the ItemListAdapter
    public ItemListAdapter(Context context, int resource, List<Item> itemList)
    {
        super(context, resource, itemList);
        this.resource=resource;
    }

    @Override
    //Creates the view containing the list of Items
    public View getView(int position, View convertView, ViewGroup parent)
    {
    	LinearLayout itemView;
    	
    	Item item = getItem(position);
    	 
        if (convertView == null)
        {            
            itemView = new LinearLayout(getContext());
            String inflater = Context.LAYOUT_INFLATER_SERVICE;
            LayoutInflater vi;
            vi = (LayoutInflater)getContext().getSystemService(inflater);
            vi.inflate(resource, itemView, true); 
        }
        else
        {
        	itemView = (LinearLayout) convertView;
        }

        TextView item_name = (TextView)itemView.findViewById(R.id.item_name);
        TextView item_descrip = (TextView)itemView.findViewById(R.id.item_descrip);
        
        item_name.setText(item.getName());
        item_descrip.setText(item.getDescription());

        return itemView;
    }

}
